#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;


char ch[110];
char in[110];


int main()
{
	int count;
	cin >> count;
	cin >> ch;
	while (count--)
	{
		int input;
		scanf("%d", &input);
		if (input == 1)
		{
			cin >> in;
			strcat(ch, in);
			cout << ch << endl;
		}
		else if (input == 2)
		{
			int start;
			int end;
			scanf("%d %d", &start, &end);
			char in[110] = { 0 };

			ch[start + end] = '\0';
			strcat(in, &ch[start]);
			strcpy(ch, in);

			cout << ch << endl;
		}
		else if (input == 3)
		{
			int cur;
			scanf("%d", &cur);

			cin >> in;
			//strcat(&ch[cur], in);
			//cout << ch << endl;

			strcat(in, &ch[cur]);
			ch[cur] = '\0';
			strcat(ch, in);
			printf("%s\n", ch);
	
		}
		else
		{
			cin >> in;
			char* ret = strstr(ch, in);
			
			printf("%d\n", ret != NULL ? (int)(ret - ch) : -1);
		}
	}
	return 0;
}